package com.powernode.settings.controller;

import com.powernode.commons.utils.ResponseData;
import com.powernode.settings.bean.RoleBean;
import com.powernode.settings.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("role")
@Api(tags = "角色管理")
public class RoleController {
    @Autowired
    private RoleService service;

    @GetMapping
    @ApiOperation("分页显示所有的角色")
    public ResponseData page(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                             @RequestParam(required = false,defaultValue = "10")Integer pageSize){
        return service.page(pageNum,pageSize);
    }


    @GetMapping("getRoleIdsByUserId")
    @ApiOperation("根据用户id查询已有的角色id")
    public ResponseData getRoleIdsByUserId(String userId){
        return service.findRoleIdsByUserId(userId);
    }

    @PutMapping("editUserRole")
    @ApiOperation("重新分配用户的角色")
    public ResponseData editUserRole(String userId,String rids){
        return service.modifyUserRole(userId,rids);
    }


    @PostMapping
    @ApiOperation("添加角色")
    public ResponseData add(@RequestBody RoleBean role){
        return service.add(role);
    }

    @PutMapping
    @ApiOperation("修改角色")
    public ResponseData edit(@RequestBody RoleBean role){
        return service.modify(role);
    }

    @DeleteMapping
    @ApiOperation("根据主键删除角色")
    public ResponseData delete(String ids){
        return service.remove(ids);
    }
}
